

package com.yz.service.impl;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.yz.common.entity.*;
import com.yz.dao.CameraDao;
import com.yz.dao.DrawingDao;
import com.yz.service.CameraService;
import com.yz.service.CheckService;
import com.yz.service.DrawingService;
import com.yz.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service("cameraService")
public class CameraServiceImpl extends ServiceImpl<CameraDao,CameraEntity> implements CameraService {
    @Autowired
    CheckService checkService;
    @Autowired
    ProjectService projectService;

    @Override
    public long selectId() {
        return this.baseMapper.selectId();
    }
    @Override
    @Transactional(rollbackFor=Exception.class)
    public void postMe(CameraEntity t) {
        CheckEntity check = new CheckEntity();
        check.setCreateAt(t.getPostTime());
        check.setCreateUser(t.getCreateUser());
        check.setName(projectService.selectById(t.getProjectId()).getName());
        if(t.getTypeWhere()==1){
            check.setNameForm(contant.type_name[4]);
        }else{
            check.setNameForm(contant.type_name[5]);
        }
        check.setProjectId(t.getProjectId());
        check.setStatus(1);
        check.setType(3);
        check.setTypeForm(t.getTypeWhere());
        if(t.getId()==0){
            this.baseMapper.insert(t);
            long id = this.baseMapper.selectId();
            check.setDataId(id);
            check.setNumber(contant.type_all_form[2]+contant.type_detail_form[12]+id);
            checkService.insert(check);
        }else{
            long id = t.getId();
            check.setDataId(id);
            check.setNumber(contant.type_all_form[2]+contant.type_detail_form[12]+id);
            checkService.update(check,new EntityWrapper<CheckEntity>().eq("number",contant.type_all_form[2]+contant.type_detail_form[12]+id));
            this.baseMapper.update(t,new EntityWrapper<CameraEntity>().eq("id",id));
        }
    }

    @Override
    @Transactional(rollbackFor=Exception.class)
    public void deleteMe(long id) {
        this.baseMapper.deleteById(id);
            checkService.deleteMe(3,id);

    }
}
